﻿using System;
namespace MyList
{
    public class Node<T>
    {
        public Node<T> Next { get; set; }
        public T Date { get; set; }
        public Node(T t)
        {
            Next = null; Date = t;

        }
    }//链表节点

    public class GeneralcList<T>     //泛列表类型
    {
        private Node<T> head;
        private Node<T> tail;
        public GeneralcList()
        {
            tail = head = null;
        }
        public Node<T> Head {
            get => head;
        }
        public void Add(T t)
        {
            Node<T> n = new Node<T>(t);
            if (tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.Next = n;
                tail = n;
            }
        }

        public  void  ForEach  (Action<Node<T>>  action)
        {
            Node<T> now = head;
            while (now != null) 
            {
                action(now);
                now = now.Next;
            } 
        }


    }   //列表类型结束
      

    class main
    {
        static void Main(string[] args)
        {
            GeneralcList<int> list = new GeneralcList<int> ();
            for(int  i=0; i < 10; i++)
            {
                list.Add(i);
            }
            list.ForEach((Node<int> node) => Console.WriteLine(node.Date));    //打印链表
            Console.WriteLine("打印链表结束");
            int max = list.Head.Date;
            list.ForEach((Node<int> node) =>{ if (max < node.Date)   max = node.Date;  });
            Console.WriteLine(max);
            Console.WriteLine("打印最大值结束");
            int min = list.Head.Date;
            list.ForEach((Node<int> node) => { if (min > node.Date) min = node.Date; });
            Console.WriteLine(min);
            Console.WriteLine("打印最小值结束");
            int mul = 0;
            list.ForEach((Node<int> node) => { mul+=node.Date; });
            Console.WriteLine(mul);
            Console.WriteLine("打印总和结束");
        }


    }



}//命名空间结束